<?php
$MSG_ERR = 0;
$_ModelPaymentMode = array('BD'=>'D','OF'=>'B','HD'=>'E');
if($GetMethodParams[1]['METRIC']=='FIXEDSIZE' && count($data['Transaction']) != $GetMethodParams[1]['LENGTH']){
	$Msg_ERROR = 'Dados Invalidos';
} elseif($GetMethodParams[1]['METRIC']=='VARSIZE' && count($data) != $GetMethodParams[1]['LENGTH']){
	$Msg_ERROR = 'Dados Invalidos';
} else {
	$row++;
	#FIX
	if(!isset($data['Receiver']['ReceiverIdNumber'])){$data['Receiver']['ReceiverIdNumber']='';}
	$fdata[0] = 'N';																																										#METHOD CODE	R	1	Char

	$ftdata .= '(&#TransactOrder#&,\''.$sysTime.'\',';
	$ftdata_extend .= '(&#ExtendedID'.$row.'#&,';
	$ftdata_income .= '(&#ExtendedID'.$row.'#&,';
	$ftdata_income .=  	$CorrProperties[1]['CorrNumero'].',&#TransactOrder#&,&#TransactTrans#&,';
	$fdata[1] = 0; 		if(!frm_fldcheck($fdata[1],'INT',8,1)){$MSG_ERR = 1;} 	$fdata[1]=isocode_replace($__sysDomains,'p'.$fdata[1],0);	$ftdata .=		$fdata[1].',';											#AGENT	R	8	Integer
	$fdata[2] = $data['TransactionDate']['Year'].'-'.$data['TransactionDate']['Month'].'-'.$data['TransactionDate']['Day'];		if(!frm_fldcheck($fdata[2],'DAT',8,1)){$MSG_ERR = 2;} 																$ftdata_income .=	'"'.$fdata[2].'",';											#DATE	R	8	YYYYMMDD
	$fdata[3] = substr($data['CodeTransaction'],strlen($data['CodeTransaction'])-10,strlen($data['CodeTransaction'])); 		if(!frm_fldcheck($fdata[3],'INT',10,1)){$MSG_ERR = 3;}																$ftdata_income .=		$fdata[3].',';									#CORRESPONDENT REFERENCE	R	10	Integer
	#$fdata[4] = $data[''];		if(!frm_fldcheck($fdata[4],'INT',8,1)){$MSG_ERR = 4;} 																$ftdata .=		'null,';												#AGENT REFERENCE	R	8	Integer
	$fdata[5] = 0; 		if(!frm_fldcheck($fdata[5],'DEC',8,1)){$MSG_ERR = 5;}																$ftdata .=		substr($fdata[5],0,6).'.'.substr($fdata[5],6,2).',';	#SENT	R	8	Decimal (8.2)
	$fdata[6] = 0; 		if(!frm_fldcheck($fdata[6],'DEC',8,1)){$MSG_ERR = 6;} 																$ftdata .=		substr($fdata[6],0,6).'.'.substr($fdata[6],6,2).',';	#FX	R	8	Decimal (8.4)
	$fdata[7] = 0;		if(!frm_fldcheck($fdata[7],'DEC',6,1)){$MSG_ERR = 7;} 																$ftdata_income .=		substr($fdata[7],0,4).'.'.substr($fdata[7],4,2).',';#COMMISION	R	6	Decimal (6.2)
	$fdata[8] = $data['Invoice']['ReceiveValue'];		if(!frm_fldcheck($fdata[8],'DEC',10,1)){$MSG_ERR = 8;} 																$ftdata .=		substr($fdata[8],0,8).'.'.substr($fdata[8],8,2).',';	#AMOUNT TO BE PAID	R	10	Decimal (10.2)
	$fdata[9] = $data['Invoice']['IsoCodeCurrency'];		if(!frm_fldcheck($fdata[9],'ALP',3,1)){$MSG_ERR = 9;} 	$fdata[9]=isocode_replace($__sysCurrency,'p'.$fdata[9],0);	$ftdata .=	$fdata[9].',';												#PAYMENT CURRENCY	R	3	Alphanumeric
	$fdata[10] = $data['Notes'];					if(!frm_fldcheck($fdata[10],'ALP',100,1)){$MSG_ERR = 10;} 														$ftdata .=	'"'.trim($fdata[10]).'",';									#MESSAGE TO RECIPIENT		100	Alphanumeric
	$fdata[11] = $data['Sender']['SenderName'];		if(!frm_fldcheck($fdata[11],'ALP',20,1)){$MSG_ERR = 11;} 															$ftdata_extend .=	'"'.trim($fdata[11]).' ';							#SENDER FIRST NAME	R	20	Alphanumeric
	$fdata[12] = '';	if(!frm_fldcheck($fdata[12],'ALP',20,1)){$MSG_ERR = 12;} 															$ftdata_extend .=		trim($fdata[12]).'",';							#SENDER LAST NAME	R	20	Alphanumeric
	$fdata[13] = $data['Sender']['SenderIdentity']['Document'];		if(!frm_fldcheck($fdata[13],'ALP',20,1)){$MSG_ERR = 13;} 															$ftdata_extend .=	'"'.trim($fdata[13]).'",';							#SENDER ID DOC NUMBER		20	Alphanumeric
	#$fdata[13] = $data['Sender']['SenderIdentity']['Document'];		if(!frm_fldcheck($fdata[13],'ALP',20,1)){$MSG_ERR = 13;} 															$ftdata_extend .=	'"'.trim($fdata[13]).'",';							#SENDER ID VALIDATY		20	Alphanumeric
	$fdata[14] = $data['Receiver']['ReceiverName'];		if(!frm_fldcheck($fdata[14],'ALP',20,1)){$MSG_ERR = 14;} 															$ftdata_extend .=	'"'.trim($fdata[14]).' ';							#RECIPIENT 1st  FIRSTNAME	R	20	Alphanumeric
	$fdata[15] = '';		if(!frm_fldcheck($fdata[15],'ALP',20,1)){$MSG_ERR = 15;} 															$ftdata_extend .=		trim($fdata[15]).' ';							#RECIPIENT 2nd FIRSTNAME		20	Alphanumeric
	$fdata[16] = '';		if(!frm_fldcheck($fdata[16],'ALP',20,1)){$MSG_ERR = 16;} 															$ftdata_extend .=		trim($fdata[16]).' ';							#RECIPIENT 1st  LASTNAME	R	20	Alphanumeric
	$fdata[17] = '';		if(!frm_fldcheck($fdata[17],'ALP',20,1)){$MSG_ERR = 17;} 															$ftdata_extend .=		trim($fdata[17]).'",';							#RECIPIENT 2nd LASTNAME		20	Alphanumeric
	$fdata[18] = $data['Receiver']['ReceiverIdNumber'];		if(!frm_fldcheck($fdata[18],'ALP',50,1)){$MSG_ERR = 18;} 															$ftdata_extend .=	'"'.trim($fdata[18]).'",';							#RECIPIENT DOCUMENT		16	Alphanumeric
	$fdata[19] = $data['Receiver']['ReceiverStreet'];		if(!frm_fldcheck($fdata[19],'ALP',50,1)){$MSG_ERR = 19;} 															$ftdata_extend .=	'"'.trim($fdata[19]).'",';							#RECIPIENT ADDRESS		50	Alphanumeric
	$fdata[20] = $data['Receiver']['ReceiverZipCode'];		if(!frm_fldcheck($fdata[20],'ALP',50,1)){$MSG_ERR = 20;} 															$ftdata_extend .=	'"'.trim($fdata[20]).'",';							#RECIPIENT NEIGHBORHOOD		50	Alphanumeric
	$fdata[21] = $data['Receiver']['ReceiverCity'];		if(!frm_fldcheck($fdata[21],'ALP',20,1)){$MSG_ERR = 21;} $fdata[21]=isocode_replace($__sysCities,'p'.$fdata[21],1);	$ftdata_extend .=	trim($fdata[21]).',';								#RECIPIENT CITY	R	20	Alphanumeric
	#$fdata[22] = $data[''];		if(!frm_fldcheck($fdata[22],'ALP',20,1)){$MSG_ERR = 22;}														 	$ftdata_extend .=	'"'.trim($fdata[22]).'",';							#RECIPIENT PROVINCE 	R	20	Alphanumeric
	$fdata[23] = $data['Receiver']['ReceiverPhone'];		if(!frm_fldcheck($fdata[23],'NUM',20,1)){$MSG_ERR = 23;} 															$ftdata_extend .=	'"'.trim($fdata[23]).'",';							#RECIPIENT PHONE	R	20	Numeric
	$fdata[24] = $data['Receiver']['ReceiverCountry_attr']['IsoCodeCountry'];		if(!frm_fldcheck($fdata[24],'ALP',2,1)){$MSG_ERR = 24;}$ftdata_extend .=	'"'.trim($fdata[24]).'",';							#RECIPIENT COUNTRY	R	2	Alphanumeric
	$fdata[25] = $_ModelPaymentMode[$data['PaymentMode']];		if(!frm_fldcheck($fdata[25],'ALP',1,1)){$MSG_ERR = 25;}$fdata[25]=isocode_replace($__sysPaymentMode,'p'.$fdata[25],0);$ftdata .=	$fdata[25].',';											#PAYMENT METHOD	R	1	Alphanumeric
	$fdata[26] = '';		if(!frm_fldcheck($fdata[26],'ALP',8,8)){$MSG_ERR = 26;}															 #	$ftdata_extend .=	'"'.$fdata[26].'",';								#BANK NACIONAL CODE	(D)	8	Alphanumeric
	$fdata[27] = $data['Receiver']['BankName'];		if(!frm_fldcheck($fdata[27],'ALP',25,1)){$MSG_ERR = 27;}$fdata[27]=isocode_replace($__sysBanks,'p'.$fdata[24].'^*^'.trim($fdata[27]).'^*^'.$fdata[26],1);$ftdata_extend .=	$fdata[27].',';	#BANK NAME	(D)	25	Alphanumeric
	$fdata[28] = $data['Receiver']['AgencyName'];		if(!frm_fldcheck($fdata[28],'ALP',25,1)){$MSG_ERR = 28;}															$ftdata_extend .=	'"'.$fdata[28].'",';								#BRANCH NUMBER	(D)	25	Alphanumeric
	$fdata[29] = '';		if(!frm_fldcheck($fdata[29],'ALP',10,1)){$MSG_ERR = 29;} $fdata[29]=isocode_replace($__sysRcvAcountType,'p'.$fdata[29],0);$ftdata_extend .=	$fdata[29].',';									#ACCOUNT TYPE	(D)	10	Alphanumeric
	$fdata[30] = $data['Receiver']['AccountNumber'];		if(!frm_fldcheck($fdata[30],'ALP',25,1)){$MSG_ERR = 30;} 															$ftdata_extend .=	'"'.$fdata[30].'",';									#ACCOUNT NUMBER	(D)	25	Alphanumeric
	$fdata[31] = $data['Destination']['CodeDestination'];		if(!frm_fldcheck($fdata[31],'ALP',8,1)){$MSG_ERR = 31;} $fdata[31]=isocode_replace($__sysAgencies,'p'.$fdata[31],0);$ftdata .=	$fdata[31].',';												#PAYING OFFICE/AGENT	(P)	8	Alphanumeric
	# Se balcao invalido adiciona �s observacoes
	if($fdata[31]==0 && $fdata[25]==0){ 													$ftdata .= '": Codigo de Agencia Invalido: '.$fdata[31].'",'; } else {$ftdata .= 'null,';}													# SYS OBS
	$fdata[32] = '';		if(!frm_fldcheck($fdata[32],'ALP',16,1)){$MSG_ERR = 32;}
	$ftdata .=	'"'.trim($fdata[32]).'",';									#MTCN REFERENCE	(P)	16	Alphanumeric
	$fdata[33] = $data['Sender']['SenderCountry_attr']['IsoCodeCountry'];		if(!frm_fldcheck($fdata[33],'INT',5,1)){$MSG_ERR = 33;} 															$ftdata_extend .=	$fdata[33].',';									#ACCOUNT NUMBER	(D)	25	Alphanumeric
	$fdata[34] = $data['Sender']['SenderStreet'];		if(!frm_fldcheck($fdata[34],'ALP',100,1)){$MSG_ERR = 34;} 															$ftdata_extend .=	'"'.$fdata[34].'",';									#ACCOUNT NUMBER	(D)	25	Alphanumeric
	$fdata[35] = $data['Sender']['SenderZipCode'];		if(!frm_fldcheck($fdata[35],'ALP',20,1)){$MSG_ERR = 35;} 															$ftdata_extend .=	'"'.$fdata[35].'",';									#ACCOUNT NUMBER	(D)	25	Alphanumeric
	$fdata[36] = $data['Sender']['SenderPhone'];		if(!frm_fldcheck($fdata[36],'ALP',20,1)){$MSG_ERR = 36;} 															$ftdata_extend .=	'"'.$fdata[36].'",';									#ACCOUNT NUMBER	(D)	25	Alphanumeric
	$fdata[37] = $data['Sender']['SenderMobile'];		if(!frm_fldcheck($fdata[37],'ALP',20,1)){$MSG_ERR = 37;} 															$ftdata_extend .=	'"'.$fdata[37].'",';									#ACCOUNT NUMBER	(D)	25	Alphanumeric
	$fdata[38] = $data['Sender']['SenderCity'];		if(!frm_fldcheck($fdata[38],'ALP',45,1)){$MSG_ERR = 38;} 															$ftdata_extend .=	isocode_replace($__sysCities,'p'.$fdata[38],1);								#ACCOUNT NUMBER	(D)	25	Alphanumeric
	$fdata[39] = $data['TransactionVersion'];		if(!frm_fldcheck($fdata[39],'INT',10,1)){$MSG_ERR = 39;} 															$ftdata_income .=	$fdata[39];								#ACCOUNT NUMBER	(D)	25	Alphanumeric

	$ftdata .= '2,2),';
	$ftdata_extend .= '),';
	$ftdata_income .= '),';

	$SUMTransactionA += $fdata[5];
	$SUMTransactionB += $fdata[8];

}